package ve.usb.ddp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import ve.usb.cohesion.runtime.CohesionAction;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import ve.usb.cohesion.runtime.HibernateUtil;
import ve.usb.ddp.hibernate.*;


/**
 * Manejo de elementos de la entidad Observacion_Paa.
 */
public class AccionesObservacion_Paa extends CohesionAction {
    
/**
     * Called by Struts for the execution of action APreCrear_observacion_Paa_paa.
     * Prepara la vista de captura de datos de una entidad para realizar una inserción.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreCrear_observacion_Paa_paa(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VCrear_observacion_Paa_paa", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FObservacion_Paa fFObservacion_Paa = FObservacion_Paa.clear(mapping, request);
             
            //Feed for combo listPaa.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(universidad, idPaa) " + 
               "from Paa").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFObservacion_Paa.setListPaa(list);
            }

            fFObservacion_Paa.setPaa(Long.parseLong((String)request.getParameter("idPaa_super")));

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APre_observacion_Paa.
     * Prepara la vista de actualización de una entidad.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APre_observacion_Paa(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_observacion_Paa", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            Long idObservacion_Paa = lookup_Long(request, "idObservacion_Paa");
            
            FObservacion_Paa fFObservacion_Paa = FObservacion_Paa.clear(mapping, request);
            Observacion_Paa observacion_Paa = (Observacion_Paa)s.load(Observacion_Paa.class, idObservacion_Paa);
            fFObservacion_Paa.setIdObservacion_Paa(observacion_Paa.getIdObservacion_Paa());

            fFObservacion_Paa.setPaa(observacion_Paa.getPaa().getIdPaa());

            fFObservacion_Paa.setFecha(observacion_Paa.getFecha().toString());
            fFObservacion_Paa.setTexto(observacion_Paa.getTexto());

            //Feed for combo listPaa.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(universidad, idPaa) " + 
               "from Paa").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFObservacion_Paa.setListPaa(list);
            }


            request.getSession().setAttribute("idPaa_super", fFObservacion_Paa.getPaa());

            request.getSession().setAttribute("idObservacion_Paa", idObservacion_Paa);
            request.getSession().setAttribute("idObservacion_Paa_super", idObservacion_Paa);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action AAct_observacion_Paa.
     * Registro de actualizaciones de Observacion_Paa.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward AAct_observacion_Paa(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_observacion_Paa", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FObservacion_Paa fFObservacion_Paa = (FObservacion_Paa)form;
            Observacion_Paa observacion_Paa = (Observacion_Paa)s.load(Observacion_Paa.class, fFObservacion_Paa.getIdObservacion_Paa());
            observacion_Paa.setFecha(new ve.usb.cohesion.runtime.LocalDate(fFObservacion_Paa.getFecha()));
            observacion_Paa.setTexto(fFObservacion_Paa.getTexto());


            //Feed for combo listPaa.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(universidad, idPaa) " + 
               "from Paa").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFObservacion_Paa.setListPaa(list);
            }


            request.getSession().setAttribute("idPaa_super", fFObservacion_Paa.getPaa());

            request.getSession().setAttribute("idObservacion_Paa", observacion_Paa.getIdObservacion_Paa());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("AAct_observacion_Paa.msg0"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action AElim_observacion_Paa.
     * Elimina el elemento seleccionado de Observacion_Paa.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward AElim_observacion_Paa(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"APre_paa", "V_observacion_Paa", };
        final int SALIDA_0 = 0;
        final int SALIDA_1 = 1;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            Long idObservacion_Paa = lookup_Long(request, "idObservacion_Paa");
            Observacion_Paa observacion_Paa = (Observacion_Paa)s.load(Observacion_Paa.class, idObservacion_Paa);

            long idPaa_super = observacion_Paa.getPaa().getIdPaa();
            observacion_Paa.getPaa().removeFromObservaciones(observacion_Paa);

            try {
                s.flush();
                request.getSession().setAttribute("idObservacion_Paa", idObservacion_Paa);

                request.getSession().setAttribute("idPaa_super", idPaa_super);

            } catch (Exception ex1) {
                ex1.printStackTrace();
                salida = SALIDA_1;
            }

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("AElim_observacion_Paa.msg0"));
        }
        if (salida==1) {
          request.setAttribute("msg",
            getResources(request).getMessage("AElim_observacion_Paa.msg1"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action ACrear_observacion_Paa.
     * Registro de la creación de un elemento de Observacion_Paa.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward ACrear_observacion_Paa(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_observacion_Paa", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FObservacion_Paa fFObservacion_Paa = (FObservacion_Paa)form;
            Observacion_Paa observacion_Paa = new Observacion_Paa();
            observacion_Paa.setFecha(new ve.usb.cohesion.runtime.LocalDate(fFObservacion_Paa.getFecha()));
            observacion_Paa.setTexto(fFObservacion_Paa.getTexto());


            {Paa obj = (Paa)s.load(Paa.class, fFObservacion_Paa.getPaa());
             obj.addToObservaciones(observacion_Paa);
            }

            s.flush();
            fFObservacion_Paa.setIdObservacion_Paa(observacion_Paa.getIdObservacion_Paa());
            //Feed for combo listPaa.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(universidad, idPaa) " + 
               "from Paa").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFObservacion_Paa.setListPaa(list);
            }


            //fFObservacion_Paa.setPaa(observacion_Paa.getPaa().getIdPaa());
            request.getSession().setAttribute("idPaa_super", fFObservacion_Paa.getPaa());

            request.getSession().setAttribute("idObservacion_Paa", observacion_Paa.getIdObservacion_Paa());
            request.getSession().setAttribute("idObservacion_Paa_super", observacion_Paa.getIdObservacion_Paa());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("ACrear_observacion_Paa.msg0"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }



}